package com.example.live.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.live.R
import com.example.live.databinding.ItemRankingBinding
import com.example.live.entity.UserEntity

import javax.inject.Inject

class RankingUserAdapter @Inject constructor(private val data:List<UserEntity>):RecyclerView.Adapter<RankingUserAdapter.commentsViewHolder>() {
    inner class commentsViewHolder(val itembinding: ItemRankingBinding):RecyclerView.ViewHolder(itembinding.root)

    private var itemOnClickListener:ItemOnClickListener ?=null
    fun setOnClickListener(listener: ItemOnClickListener){
        this.itemOnClickListener = listener
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): commentsViewHolder {
        return commentsViewHolder(ItemRankingBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: commentsViewHolder, position: Int) {
        val entity = data[position]
        holder.itembinding.apply {
            //GlideImgLoader.loadImage(guanzhuUser.context,entity.headImg,guanzhuUser)
            tvNumber.setText("${position+1}")
            ivIcon.setBackgroundResource(R.drawable.ic_mine_mine)
            tvName.setText(entity.username)
            tvHot.setText("${entity.id}")
            root.setOnClickListener {
                itemOnClickListener?.onClick(it,position)
            }
        }
    }

    interface ItemOnClickListener{
        fun onClick(view:View,position: Int){

        }
    }
}